#pragma once

#include <QtWidgets/QMainWindow>
#include "ui_MyTcpServer.h"
#include "../Include/HPSocket/HPSocket.h"
#include "../Include/HPSocket/SocketInterface.h"
#include "../MyTestEcho/selfdefine.h"


class MyTcpServer : public QMainWindow,public CTcpPullServerListener
{
    Q_OBJECT
signals:
    void signal_log_msg(const QString&);
    void signal_widget_state(WidgetState);
private slots:
    void on_pushButton_start_clicked();
    void on_pushButton_stop_clicked();
    void on_pushButton_disconn_clicked();

    void SetWidgetState(WidgetState state);
    void LogMsg(const QString& info);
public:
    MyTcpServer(QWidget *parent = Q_NULLPTR);
protected:
    void OnInitDialog();
    void InitSlot();
protected:
    virtual EnHandleResult OnPrepareListen(ITcpServer* pSender, SOCKET soListen);
    virtual EnHandleResult OnAccept(ITcpServer* pSender, CONNID dwConnID, UINT_PTR soClient);
    virtual EnHandleResult OnHandShake(ITcpServer* pSender, CONNID dwConnID);
    virtual EnHandleResult OnReceive(ITcpServer* pSender, CONNID dwConnID, int iLength);
    virtual EnHandleResult OnSend(ITcpServer* pSender, CONNID dwConnID, const BYTE* pData, int iLength);
    virtual EnHandleResult OnShutdown(ITcpServer* pSender);
    virtual EnHandleResult OnClose(ITcpServer* pSender, CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode);

private:
    Ui::MyTcpServerClass ui;
    CTcpPullServerPtr m_server;
    WidgetState m_widget_state;
};
